import 'package:flutter/material.dart';
import 'package:get/get.dart';

import 'logic.dart';

class ProgramListPage extends StatelessWidget {
  const ProgramListPage({super.key});

  @override
  Widget build(BuildContext context) {
    final ProgramListLogic logic = Get.find<ProgramListLogic>();
    final state = logic.state;
    return Scaffold(
      appBar: AppBar(title: const Text("程序列表")),
      body: Obx(() {
        if (state.fList.isEmpty) {
          return const Center(child: Text("正在获取"));
        }
        return ListView.separated(
          shrinkWrap: true,
          physics: const NeverScrollableScrollPhysics(),
          itemCount: state.fList.length,
          itemBuilder: (BuildContext context, int index) {
            var bean = state.fList[index];
            return Container(
              padding: const EdgeInsets.all(8.0),
              child: Row(children: [
                Expanded(
                  child: Padding(
                    padding: const EdgeInsets.all(5),
                    child: Text(bean,
                        style: const TextStyle(
                            fontSize: 20, fontWeight: FontWeight.bold)),
                  ),
                ),
                InkWell(
                    onTap: () {
                      logic.runFunction(bean);
                    },
                    child: const Padding(
                        padding:
                            EdgeInsets.symmetric(horizontal: 10, vertical: 8),
                        child: Text("运行",
                            style: TextStyle(
                                color: Colors.blue,
                                fontWeight: FontWeight.bold)))),
                InkWell(
                    onTap: () {
                      logic.editSingleConfig(bean);
                    },
                    child: const Padding(
                        padding:
                            EdgeInsets.symmetric(horizontal: 10, vertical: 8),
                        child: Text("配置",
                            style: TextStyle(
                                color: Colors.blue,
                                fontWeight: FontWeight.bold))))
              ]),
            );
          },
          separatorBuilder: (BuildContext context, int index) {
            return Divider(
              color: Colors.grey.withAlpha(20),
            );
          },
        );
      }),
    );
  }
}
